<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      canvas {
        border: 1px solid red;
      }
    </style>
  </head>
  <body>
    <canvas id="canvas" width="400" height="300"></canvas>

    <script>
      let canvas = document.querySelector("#canvas");
      let context = canvas.getContext("2d");

      let arr = [16, 2, 8, 11, 9, 14, 4, 3, 4, 15, 25];
      let max = Math.max(...arr);

      for (let i = 0; i < arr.length; i++) {
        context.beginPath();

        let x = (i + 1) * (300 / arr.length);
        let y = 300 - arr[i] * (300 / max);
        context.arc(x, y, 3, 0, 2 * Math.PI);
        context.fill();
        context.closePath();
      }

      context.beginPath();
      context.lineWidth = 3;

      for (let i = 0; i < arr.length; i++) {
        let x = (i + 1) * (300 / arr.length);
        let y = 300 - arr[i] * (300 / max);

        if (i) {
          context.lineTo(x, y);
        } else {
          context.moveTo(x, y);
        }
        // context.strokeStyle = "red";
        context.strokeStyle='hsl(120,100%,50%)';
        
        context.stroke();
        // context.closePath();
      }

      // 柱状图  饼状图 环状图
    </script>
  </body>
</html>
